package com.youle.contoller;

import com.youle.enums.ExceptionEnum;
import com.youle.exception.YLException;
import com.youle.item.pojo.Spu;
import com.youle.item.vo.ItemVo;
import com.youle.service.ItemSpuService;
import com.youle.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by
 *  用于商品的controller
 *  http://api.leyou.com/api/item/spu/page?key=&saleable=true&page=1&rows=5
 * @author touni
 * @date 2019/4/18
 * @time 14:55
 */
@RestController
@RequestMapping("spu")
public class ItemSpuController {

    @Autowired
    private ItemSpuService itemSpuService;


    @RequestMapping("page")
    public ResponseEntity<PageResult<ItemVo>> listItem(String key,
                                                       Boolean saleable,
                                                       @RequestParam(defaultValue = "1") Integer page,
                                                       @RequestParam(defaultValue = "10") Integer rows){
        return itemSpuService.listItemSpu(key,saleable,page,rows);
    }



    @RequestMapping("detail/{id}")
    public ResponseEntity<Spu> queryDetailById(@PathVariable Long id){
        if (null == id){ throw new YLException(ExceptionEnum.PARAM_NOT_BE_NULL); }
        return itemSpuService.queryDetailById(id);
    }










}
